package com.example.controller;

import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.pojo.Task;
import com.example.service.PlanService;
import com.example.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                       String taskName, String status,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageBean pageBean = taskService.page(page, pageSize, taskName, status, begin, end);
        System.out.println(taskName);
        return Result.success(pageBean);
    }

    @GetMapping("/sx")
    public Result pages(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                       String taskName, String status,String schedulingMode,String priorityRules,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageBean pageBean = taskService.pages(page, pageSize, taskName, status,schedulingMode,priorityRules, begin, end);
        return Result.success(pageBean);
    }
    @GetMapping("/id")
    public Result setTaskId(){
        List<Task> tasks = taskService.selectAll();
        return Result.success(tasks);
    }

    @PostMapping
    public Result add(@RequestBody Task task) {
        taskService.add(task);

        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Task task) {
        taskService.update(task);
        return Result.success();
    }

    @PutMapping("/set")
    public Result updates(@RequestBody Task task) {
        taskService.updates(task);
        return Result.success();
    }
}
